﻿using ImGuiNET;
using System;
using System.Collections.Generic;
using System.Text;

namespace TTEngine.Editor
{
    static class ReflectionGUI
    {
        public static void OnGUI(object _obj)
        {
            var type = _obj.GetType();
            foreach (var f in type.GetFields())
            {
                if (f.IsPublic)
                {
                    if (f.FieldType == typeof(string))
                    {
                        string srcstr = f.GetValue(_obj) as string;
                        if (srcstr == null) srcstr = "";
                        if (ImGui.InputText(f.Name, ref srcstr, 256))
                        {
                            f.SetValue(_obj, srcstr);
                        }
                    }
                    if (f.FieldType == typeof(int))
                    {
                        var srcint = (int)f.GetValue(_obj);
                        if (ImGui.InputInt(f.Name, ref srcint))
                        {
                            f.SetValue(_obj, srcint);
                        }
                    }
                }
            }
        }
    }
}
